package control;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Actor;
public class EditActor extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditActor() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String acid = request.getParameter("acid");
		String n = request.getParameter("n");
		String bio = request.getParameter("bio");
		Actor actor = new Actor(Integer.parseInt(acid), n, bio);
		if (actor.checkNewName()!="") {
			request.setAttribute("n", n);
			request.setAttribute("bio", bio);
			request.setAttribute("en",actor.checkNewName());
			RequestDispatcher transferexist = getServletContext().getRequestDispatcher("/a/actor.jsp?site=e");
			transferexist.forward(request, response);
		} else {
			actor.upDate();
			request.setAttribute("m", "edit-acok");
			request.setAttribute("r","vac");
			RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
			transfer.forward(request, response);
		}
	}

}
